﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility.DBConnection.SqlSever
{
    /// <summary>
    /// 加装一层 封装Dbsession资源  --设计模式之单例模式
    /// </summary>
    public class SqlDbSessionResource
    {
        #region 单例
        private static readonly object m_InstanceLocker = new object();

        private SqlDbSessionResource()
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                if (ConfigManager.AppSettings.AllKeys.Contains("ConnectionString"))
                {
                    ConnectionString = ConfigManager.AppSettings["ConnectionString"].Value;
                }
            }
        }

        private static SqlDbSessionResource m_Instance;

        public static SqlDbSessionResource Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    lock (m_InstanceLocker)
                    {
                        if (m_Instance == null)
                        {
                            m_Instance = new SqlDbSessionResource();
                        }
                    }
                }
                return m_Instance;
            }
            set { m_Instance = value; }
        }
        #endregion

        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string ConnectionString = "";

        /// <summary>
        /// 初始化连接紫都城
        /// </summary>
        /// <param name="connectionString"></param>
        public void InitConnectionString(string connectionString)
        {
            ConnectionString = connectionString;
        }
    }
}
